<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left"><Breadcrumb /></div>
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <SearchBar :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"
          style="width: 99.9%"
          row-key="id"
          :cell-style="cellStyle"
          @cell-click="cellClick"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <el-table-column
            type="selection"
            align="center"
            width="50"
          />
          <el-table-column label="提交状态">
            <template slot-scope="scope">
              <div v-if="scope.row.status=='1'" class="submitted">
                <div class="submitted_circle" />
                已提交
              </div>
              <div v-if="scope.row.status=='0'" class="not_submit">
                <div class="not_submit_circle" />
                未提交
              </div>
            </template>
          </el-table-column>
          <Column v-for="(column,index) in tableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
          <el-table-column label="回复结果" min-width="100">
            <template slot-scope="scope">
              <div v-if="scope.row.responseStatus=='1'" class="adequate_space">
                <svg-icon icon-class="通过" />
                已回复
              </div>
              <div v-if="scope.row.responseStatus=='0'&&scope.row.status=='1'" class="insufficient_space">
                <svg-icon icon-class="不足" />
                待回复
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right" width="180">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.status=='0'"
                type="text"
                @click.stop="edit(scope.row)"
              >编辑</el-button>
              <span v-else class="el-button--text button_grey">编辑</span>
              <el-button
                v-if="scope.row.status=='1'&&scope.row.responseStatus=='0'"
                type="text"
                @click.stop="cancel(scope.row)"
              >撤销</el-button>
              <span v-else class="el-button--text button_grey">撤销</span>
              <el-button
                type="text"
                @click.stop="deleteOne(scope.row)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import { list, remove, getInfo, addOrUpdate } from '@/api/superManage/systemMonitoring/feedBack'
// import { list } from '@/api/superManage/diskSpaceMonitoring'
import { mapGetters } from 'vuex'
import Column from '@/components/JLink/common/Column.vue'
import AddOrUpdate from './AddOrUpdate.vue'
import showDetail from './showDetail.vue'
export default {
  name: 'Index',
  components: { Column },
  computed: {
    ...mapGetters([
      'companyId'
    ])
  },
  data() {
    return {
      loading: false,
      pageId: '意见反馈', // 页面唯一标识
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      companyOptions: [],
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'statusName', label: '状态', canOrder: false, width: '100' },
        { prop: 'type', label: '问题方向' },
        { prop: 'createTime', label: '提交时间' },
        { prop: 'userName', label: '提交人' },
        { prop: 'handlePersonnel', label: '回复人' },
        { prop: 'handleTime', label: '回复时间' }
      ],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        { prop: 'status', label: '状态', type: 'select', optionsName: 'statusOptions' },
        { prop: 'type', label: '问题方向', type: 'select', optionsName: 'typeOptions' },
        { prop: 'handleTime', label: '提交时间', type: 'time' },
        { prop: 'responseStatus', label: '回复结果', type: 'select', optionsName: 'resultOptions' }
      ],
      statusOptions: [
        { value: undefined, label: '全部' },
        { value: '0', label: '未提交' },
        { value: '1', label: '已提交' }
      ],
      resultOptions: [
        { value: undefined, label: '全部' },
        { value: '0', label: '待回复' },
        { value: '1', label: '已回复' }
      ],
      typeOptions: [
        { value: undefined, label: '全部' },
        { value: '漏洞(bug)', label: '漏洞(bug)' },
        { value: '产品优化', label: '产品优化' },
        { value: '新需求', label: '新需求' }
      ],
      operationData: [ // 右上角的操作按钮
        { label: '新增', perm: '' },
        { label: '批量删除', perm: '' },
        { label: '页面配置', perm: '' }
      ]

    }
  },
  created() {
  },
  mounted() {
    this.$nextTick(() => {
      this.tableHeight = this.$refs.table_container.offsetHeight
    })
  },
  methods: {
    cellStyle({ row, column }) {
      if (column.property == 'type') {
        return {
          cursor: 'pointer',
          color: '#387bfc'
        }
      }
    },
    cellClick(row, column, cell) {
      switch (column.property) {
        case 'type':
          this.showDetail(row)
          break
      }
    },
    add() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {}// props
        },
        area: ['900px', '725px'],
        title: '新增意见反馈', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    edit(row) {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            id: row[this.mainId]
          }// props
        },
        area: ['900px', '725px'],
        title: '编辑意见反馈', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    showDetail(row) {
      getInfo(row.id).then(res => {
        this.$layer.iframe({// 弹框
          content: {
            content: showDetail, // 传递的组件对象
            parent: this, // 当前的vue对象
            data: {
              showData: res.data
            }// props
          },
          area: ['900px', '700px'],
          title: '问题详情', // 标题
          shadeClose: false // 点击遮罩是否关闭
        })
      })
    },
    getList() {
      this.loading = true
      list({ ...this.pageData }).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
        })
      }).finally(() => {
        this.loading = false
      })
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    },
    cancel(row) {
      getInfo(row.id).then(res => {
        const _this = this
        this.$confirm('确定要撤销吗', '撤销确认', {
          confirmButtonText: '确定',
          cancelButtonText: '取消', cancelButtonClass: 'cancelConfirm',
          type: 'warning'
        }).then(function() {
          res.data.status = '0'
          addOrUpdate(res.data).then(res2 => {
            _this.$message({
              message: res2.msg,
              type: 'success'
            })
            _this.getList()
          })
        }).catch(() => {})
      })
    },
    deleteOne(row) {
      const _this = this
      this.$confirm('确定要删除吗', '删除确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消', cancelButtonClass: 'cancelConfirm',
        type: 'warning'
      }).then(function() {
        remove(row[_this.mainId]).then(res => {
          _this.$message({
            message: res.msg,
            type: 'success'
          })
          _this.selectionsAll = []
          _this.getList()
        })
      }).catch(() => {})
    },
    // 当前页的删除接口
    deleteMethod(deleteIds) {
      return remove(deleteIds)
    }
  }
}
</script>

  <style lang="less" scoped>
    .submitted{
      display: flex;
      align-items: center;
      .submitted_circle{
        height: 8px;
        width: 8px;
        background-color: #19BE6B;
        border-radius:4px;
        margin-right: 5px;
      }
    }
    .not_submit{
       display: flex;
      align-items: center;
      .not_submit_circle{
        height: 8px;
        width: 8px;
        background-color: #FF9900;
        border-radius:4px;
        margin-right: 5px;
      }
    }
    .adequate_space{
        color: #19BE6B;
        background-color:rgb(223, 249, 241) ;
        border-radius: 3px;
        padding: 3px 0;
        width: 100px;
        text-align: center;
    }
    .insufficient_space{
        color: #FF9900;
        background-color:rgb(255, 244, 237) ;
        border-radius: 3px;
        padding: 3px 0;
        width: 100px;
        text-align: center;
    }
    .full_space{
        color: #F56C6C;
        background-color:rgb(255, 235, 236) ;
        border-radius: 3px;
        padding: 3px 0;
        width: 100px;
        text-align: center;
    }
  </style>

